package com.guigu.basedservice.controller;

import com.github.pagehelper.PageInfo;
import com.guigu.basedservice.dto.CarSeriesInfoDto;
import com.guigu.basedservice.entity.BaseCarBrand;
import com.guigu.basedservice.entity.BaseCarCategory;
import com.guigu.basedservice.service.BaseCarCategoryService;
import com.guigu.basedservice.service.CarSeriesInfoService;
import com.guigu.basedservice.utils.UniqueNumberGenerator;
import com.guigu.basedservice.vo.CarSeriesInfoVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.Date;

/**
 * @author heyuhang
 * @create 2024/9/19
 */
@CrossOrigin
@RestController
@RequestMapping("/basedservice/car-series-info")
public class CarSeriesInfoController {

    @Autowired
    private CarSeriesInfoService carSeriesInfoService;

    @Autowired()
    private BaseCarCategoryService baseCarCategoryService;

    @RequestMapping("/getCarSeriesInfo/{currentPage}/{pageSize}")
    public PageInfo<CarSeriesInfoDto> getCarSeriesInfo(
            @PathVariable Integer currentPage,
            @PathVariable Integer pageSize,
            @RequestBody CarSeriesInfoVo vo
    ){
        System.out.println("vo++++"+vo);
        PageInfo<CarSeriesInfoDto> carSeriesInfo = carSeriesInfoService.getCarSeriesInfo(currentPage,pageSize,vo);
        return carSeriesInfo;
    }

    @RequestMapping("/getOne/{id}")
    public BaseCarCategory getOne(@PathVariable("id") String id){
        return baseCarCategoryService.getById(id);
    }

    @ApiOperation("添加BaseCarCategory数据")
    @RequestMapping("/addBaseCarCategory")
    public Boolean addBaseCarCategory(@RequestBody BaseCarCategory baseCarCategory){
        baseCarCategory.setCategoryUuid(UniqueNumberGenerator.generateUniqueNumber());
        baseCarCategory.setVersion(BigDecimal.valueOf(0));
        boolean save = baseCarCategoryService.save(baseCarCategory);
        return true;
    }

    @ApiOperation("修改BaseCarCategory数据")
    @RequestMapping("/update")
    public Boolean update(@RequestBody BaseCarCategory baseCarCategory){
        System.out.println("baseCarCategory++++"+baseCarCategory);
        return baseCarCategoryService.updateById(baseCarCategory);
    }

    @RequestMapping("/delete/{categoryUuid}")
    public Boolean delete(@PathVariable String categoryUuid){
        return baseCarCategoryService.removeById(categoryUuid);
    }



}
